package com.baizw.cultivation.config;

import com.baizw.cultivation.common.interceptor.NoRepeatSubmitInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: 跨域处理配置
 * @Author: 剧终1204
 * @create: 2018年 03月 22日 16:32
 * @Copyright: 2018 http://www.cnns.net All rights reserved.
 * 注意：本内容仅限于深圳安络科技公司内部传阅，禁止外泄以及用于其他的商业目
 */
@Configuration
public class CorsDomainConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new NoRepeatSubmitInterceptor()).addPathPatterns("/**");
    }
}
